
package com.arcsoft.crud.limitTime.task;

import java.util.Date;
import java.util.concurrent.CountDownLatch;

import com.arcsoft.crud.Constants.Global;
import com.arcsoft.crud.limitTime.base.BenchmarkTimeTask;
import com.arcsoft.crud.util.ConnectionDB;
import com.arcsoft.log.entity.OptimizeAnalyzeLog;

public class InsertTimeTask extends BenchmarkTimeTask{

	public InsertTimeTask(int threadIndex, CountDownLatch parent, int printInfoInterval,
			String taskLogTable) {
		super(threadIndex, parent, printInfoInterval, taskLogTable);
	}
	
	@Override
	public String execute(){
		ConnectionDB db = new ConnectionDB();
        
        String sql = "insert into people(name, age,password,name1,password1,name2,score,score1,score2,score4) values(?,?,?,?,?,?,?,?,?,?)";
         
        Object arrays[] = {"jack"+threadIndex, (int)(Math.random()*100),
        		randomString((int)(Math.random()*10)),randomString((int)(Math.random()*10)),
        		randomString((int)(Math.random()*10)),randomString((int)(Math.random()*10)),
        		Math.random()*100,Math.random()*100,randomString((int)(Math.random()*10)),randomString((int)(Math.random()*10))
        	  };
        
        db.updateBySql(sql, arrays);
        return parseSql(sql, arrays);
	}
	
	@Override
	public void logInfo(Date startTime, Date endTime, String requestDetail, int extendTime){
		String sceneDesc = Global.OPERATOR_TYPE_INSERT+"-"+Global.THREAD_COUNT+"C-"+Global.WARMTIME+"W-"+Global.EXECUTE_TIME+"E";//场景名命名规则 操作类型-并发数C-预热时间W-执行时间E
		
		OptimizeAnalyzeLog optimizeAnalyzeLog = new OptimizeAnalyzeLog
					(sceneDesc,Global.OPERATOR_TYPE_INSERT,startTime, endTime, extendTime, requestDetail);
		
		insertLog(optimizeAnalyzeLog);
	}

}
